package lily.ui.bookshelf;

import lily.phs.urh.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 档案袋的布局类
 * @author heckassitant
 *
 */
public class ProfileView extends LinearLayout {
	
	private static final String TAG = "case";
	private static final float ASPECTRATIO = 1.4f;//纵横比（高：宽）
	private static final float WIDTHRATIO = 4.0f/20;//控件宽：屏幕宽（竖屏）
	
//	public TextView tv;
//	public ImageView iv;
	public Button button;
	public int FileWidth;
	public int FileHeight;

	public ProfileView(Context context) {
		super(context);
		
		this.setOrientation(LinearLayout.VERTICAL);
		this.setPadding(0, 0, 0, 0);
		this.setGravity(Gravity.CENTER);
//		this.setBackgroundColor(Color.WHITE);
		
		//计算控件尺寸
		WindowSizeUtil util = new WindowSizeUtil(context);
		int w = (util.ScreenWidth<util.ScreenHeight)?util.ScreenWidth:util.ScreenHeight;//竖屏时屏幕宽度
		FileWidth = Math.round(w * WIDTHRATIO)+this.getPaddingLeft()+this.getPaddingRight();
		FileHeight = Math.round(FileWidth * ASPECTRATIO);
		
		Drawable db = context.getResources().getDrawable(R.drawable.profile);
		//db.setBounds(0, 0, FileWidth, FileWidth);
		Bitmap bmp=ImageUtil.drawableToBitmap(db);
	    bmp=ImageUtil.zoomBitmap(bmp, FileWidth, FileHeight);
	    BitmapDrawable bitDb = new BitmapDrawable(bmp);
	    this.setBackgroundDrawable(bitDb);
	    
	    button = new Button(context);
	    button.setText("健康档案");
	    button.setTextColor(Color.WHITE);
	    button.setBackgroundColor(00000000);
	    button.setGravity(Gravity.CENTER);
	    button.setTextSize(25);
	    LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(button,lp);
		
	    
//		//显示档案名
//		this.tv = new TextView(context);
//		this.tv.setTextColor(Color.CYAN);
////		this.tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
////		this.tv.setLines(2);
//		this.tv.setGravity(Gravity.CENTER);
//		//this.tv.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.input_over));
//		this.addView(
//				tv,FileWidth,FileHeight-FileWidth);
////				MeasureSpec.makeMeasureSpec(FileWidth, MeasureSpec.EXACTLY),
////				MeasureSpec.makeMeasureSpec(FileHeight-FileWidth, MeasureSpec.EXACTLY)
////				);
//		
//		//显示档案的图片
//		this.iv = new ImageView(context);
//		Drawable db = context.getResources().getDrawable(R.drawable.profile2);
//		//db.setBounds(0, 0, FileWidth, FileWidth);
//		Bitmap bmp=ImageUtil.drawableToBitmap(db);
//	    bmp=ImageUtil.zoomBitmap(bmp, FileWidth, FileWidth);
//		this.iv.setImageBitmap(bmp);
//		this.iv.setFocusable(true);
//		this.iv.setClickable(true);
//		//this.iv.setPadding(0, 10, 0, 0);
//		this.addView(
//				iv, FileWidth,FileWidth);
////				MeasureSpec.makeMeasureSpec(FileWidth, MeasureSpec.EXACTLY),
////				MeasureSpec.makeMeasureSpec(FileWidth, MeasureSpec.EXACTLY));//图片高=宽
//		
		this.setFocusable(false);
		this.setClickable(false);

		//Log.i(TAG, "file.width="+FileWidth+",file.height="+FileHeight);
		
	}
	

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
//		Log.i(TAG, "file.onLayout");
		super.onLayout(changed, l, t, r, b);
		
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
//		Log.i(TAG, "file.onMeasure");
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		
	}
	
}


